home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_13_11 / phillip2 / half.c < prev    next >
C/C++ Source or Header  |  1993-06-25  |  4KB  |  140 lines

  1.  
  2.  
  3.     /***********************************************
  4.     *
  5.     *    file d:\cips\half.c
  6.     *
  7.     *    Functions: This file contains
  8.     *       main
  9.     *
  10.     *    Purpose:
  11.     *       This file contains the main calling
  12.     *       routine for a program which shrinks
  13.     *       an image in half (600x600 to a
  14.     *       300x300).  The output image will
  15.     *       always be an even multiple of
  16.     *       ROWS and COLS.
  17.     *
  18.     *    External Calls:
  19.     *       gin.c - get_image_name
  20.     *       numcvrt.c - get_integer
  21.     *                   int_convert
  22.     *       tiff.c - read_tiff_header
  23.     *       scale.c - shrink_image_array
  24.     *
  25.     *    Modifications:
  26.     *       25 April 1992 - created
  27.     *
  28.     *************************************************/
  29.  
  30. #include "cips.h"
  31.  
  32.  
  33.  
  34. short the_image[ROWS][COLS];
  35. short out_image[ROWS][COLS];
  36.  
  37. main(argc, argv)
  38.    int argc;
  39.    char *argv[];
  40. {
  41.  
  42.    char     method[80], name[80], name2[80];
  43.    int      count, i, j, length, width,
  44.             il, ie, ll, le;
  45.    struct   tiff_header_struct image_header;
  46.  
  47.    my_clear_text_screen();
  48.  
  49.        /******************************************
  50.        *
  51.        *   Interpret the command line parameters.
  52.        *
  53.        *******************************************/
  54.  
  55.    if(argc < 4 || argc > 4){
  56.     printf(
  57.      "\n"
  58.      "\n usage: half in-file out-file method"
  59.      "\n        method can be Average, Median, Corner"
  60.      "\n");
  61.     exit(0);
  62.    }
  63.  
  64.    strcpy(name,   argv[1]);
  65.    strcpy(name2,  argv[2]);
  66.    strcpy(method, argv[3]);
  67.  
  68.    if(method[0] != 'A' &&
  69.       method[0] != 'a' &&
  70.       method[0] != 'M' &&
  71.       method[0] != 'm' &&
  72.       method[0] != 'C' &&
  73.       method[0] != 'c'){
  74.       printf("\nERROR: Did not enter a valid method"
  75.              "\n       The valid methods are:"
  76.              "\n       Average, Median, Corner");
  77.        printf(
  78.         "\n"
  79.         "\n usage: half in-file out-file method"
  80.         "\n        method can be Average, Median, "
  81.         "Corner"
  82.         "\n");
  83.       exit(-2);
  84.    }
  85.  
  86.    il = 1;
  87.    ie = 1;
  88.    ll = ROWS+1;
  89.    le = COLS+1;
  90.  
  91.        /********************************************
  92.        *
  93.        *   Read the input image header and setup
  94.        *   the looping counters.
  95.        *
  96.        *   Halve the looping counters.
  97.        *
  98.        *   Create the output image.
  99.        *
  100.        *********************************************/
  101.  
  102.    read_tiff_header(name, &image_header);
  103.  
  104.    length = (ROWS-10 + image_header.image_length)/ROWS;
  105.    width  = (COLS-10 + image_header.image_width)/COLS;
  106.    if( (length % 2) != 0) length++;
  107.    if( (width  % 2) != 0) width++;
  108.    length = length/2;
  109.    width  = width/2;
  110.    count  = 1;
  111.  
  112.    image_header.image_length = length*ROWS;
  113.    image_header.image_width  = width*COLS;
  114.    create_allocate_tiff_file(name2, &image_header,
  115.                              out_image);
  116.  
  117.        /*********************************************
  118.        *
  119.        *   Read and shrink each 200x200 area of the
  120.        *   input image and write them to the output
  121.        *   image.
  122.        *
  123.        **********************************************/
  124.  
  125.    count = 1;
  126.    for(i=0; i<length; i++){
  127.       for(j=0; j<width; j++){
  128.          printf("\nrunning %d of %d", 
  129.                 count++, length*width);
  130.          shrink_image_array(name, name2,
  131.                             the_image, out_image,
  132.                             il+i*ROWS*2, ie+j*COLS*2,
  133.                             ll+i*ROWS*2, le+j*COLS*2,
  134.                             il+i*ROWS, ie+j*COLS,
  135.                             ll+i*ROWS, le+j*COLS,
  136.                              2, method);
  137.       }  /* ends loop over j */
  138.    }  /* ends loop over i */
  139. }  /* ends main  */
  140.